package com.avic.rong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.listener.CategoryItemOnClickListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Creater: Created by wangyz on 2017/1/10.
 * Email: 936804097@qq.com
 */

public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.CategoryViewHolder> {


    private Context mContext;
    private List<String> mData = new ArrayList<>();


    public CategoryAdapter(Context context) {
        this.mContext = context;
        mData.add("标准");
        mData.add("图书");
        mData.add("实用文档");
        mData.add("软件工具");
    }

    @Override
    public CategoryAdapter.CategoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.view_category, parent, false);
        CategoryViewHolder holder = new CategoryViewHolder(view, viewType);

        return holder;
    }

    @Override
    public void onBindViewHolder(CategoryAdapter.CategoryViewHolder holder, final int position) {
//        GlideUtil.getInstance().loadImageWang(mContext, holder.img_category, mData.get(position).getCatIcon(),
//                DensityUtils.dp2px(mContext, 45), DensityUtils.dp2px(mContext, 45),
//                R.mipmap.icon_type);
        if (position == 0){
            holder.img_category.setImageResource(R.mipmap.biaozhun);
        }else if(position == 1){
            holder.img_category.setImageResource(R.mipmap.tushu);
        }else if(position == 2){
            holder.img_category.setImageResource(R.mipmap.zhishifuwu);
        }else if(position == 3){
            holder.img_category.setImageResource(R.mipmap.zhuantiku);
        }
        holder.tv_category_name.setText(mData.get(position));
        holder.itemView.setOnClickListener(new CategoryItemOnClickListener(mContext, position));

    }

    @Override
    public int getItemCount() {
        return mData.size();
    }


    class CategoryViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_category_name)
        TextView tv_category_name;
        @BindView(R.id.img_category)
        ImageView img_category;

        public CategoryViewHolder(View itemView, int type) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
